import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
/**
 * Class to test high scores
 * 
 * @author (Borland) 
 * @version (12-16-11)
 */
public class HighScoreTest extends JFrame implements ActionListener
{

    // instance variables - replace the example below with your own
    private int x;
    JLabel nameLabel = new JLabel("name");
    JLabel scoreLabel = new JLabel("score");    
    JTextField name = new JTextField(8);
    JTextField score = new JTextField(3);    
    JButton setScore= new JButton ("Test Score");
    JButton getScore = new JButton ("Set Score");
    JTextArea messageArea= new JTextArea(20,25);

    HighScore onlineScores=new HighScore("TestIt");

    public static void main (String[] args)
    {
        HighScoreTest p = new HighScoreTest();
        p.init();
        p.setSize(520,520);
        p.setVisible(true);
    }

    /**
     * Called by the browser or applet viewer to inform this JApplet that it
     * has been loaded into the system. It is always called before the first 
     * time that the start method is called.
     */
    public void init()
    {
        Container screen = getContentPane();
        screen.setBackground(Color.gray);
        screen.setLayout (new FlowLayout() );
        screen.add(nameLabel);
        screen.add(name);
        screen.add(scoreLabel);
        screen.add(score);
        screen.add(setScore);
        screen.add(getScore);
        screen.add(messageArea);
        setScore.addActionListener(this);
        getScore.addActionListener(this);        
    }

    public void paint(Graphics g)
    {
        super.paint(g);

    }

    public void actionPerformed(ActionEvent thisEvent)
    {
        Object source = thisEvent.getSource();

        if (source == setScore)
        {           
            double scoreValue=Double.parseDouble(score.getText());
            String nameString=name.getText();
            String returnInfo=onlineScores.setScore(scoreValue,nameString);
            messageArea.append(returnInfo);
        }
        if (source == getScore)
        {           
            double highScore=onlineScores.getHighScore();
            String highName=onlineScores.getHighScoreName();
             messageArea.append("\n"+highName+": "+highScore);
        }
    }
}
